#### SENSITIVITY TEST: Heterogeneous effects between house and senate ####
general_house <- general %>% 
  filter(race == "House")

general_senate <- general %>% 
  filter(race == "Senate")

primary_house <- primary %>% 
  filter(race == "House")

primary_senate <- primary %>% 
  filter(race == "Senate")

# Primary congressional elections
primary_controls_no_election_type = c("white + incumbent + female + lchars + fchars + num_prim_opps + factor(party) + factor(year) + factor(state)")
general_controls_no_election_type = c("white + incumbent + female + lchars + fchars + factor(party) + factor(year) + factor(state)")

mod_primary_house <- lm(formula(paste(dv_prim, "~", iv_all_names, "+", primary_controls_no_election_type)),
                      data = primary_house)

primary_house_r2 <- get_r2(mod_primary_house)
mod_primary_house <- get_clusters(mod_primary_house)

mod_primary_senate <- lm(formula(paste(dv_prim, "~", iv_all_names, "+", primary_controls_no_election_type)),
                        data = primary_senate)

primary_senate_r2 <- get_r2(mod_primary_senate)
mod_primary_senate <- get_clusters(mod_primary_senate)

# general congressional elections
mod_general_house <- lm(formula(paste(dv_gen, "~", iv_all_names, "+", general_controls_no_election_type)),
                        data = general_house)


general_house_r2 <- get_r2(mod_general_house)
mod_general_house <- get_clusters(mod_general_house)

mod_general_senate <- lm(formula(paste(dv_gen, "~", iv_all_names, "+", general_controls_no_election_type)),
                         data = general_senate)

general_senate_r2 <- get_r2(mod_general_senate)
mod_general_senate <- get_clusters(mod_general_senate)

mods <- list(mod_general_house, mod_general_senate, mod_primary_house, mod_primary_senate)
stargazer(mods,
          type = "latex",
          title = "Relationship Between Name Fluency and Vote Share, Heterogeneity by Chamber",
          style = style,
          star.cutoffs = star.cutoffs,
          star.char = star.char,
          column.labels = c("General (House)", "General (Senate)", "Primary (House)", "Primary (Senate)"),
          keep.stat = keep.stat,
          notes = notes,
          keep = keep_congress,
          covariate.labels = covariate.labels_congress,
          font.size = "footnotesize",
          model.names = F,
          add.lines=list(c("Year FE", "\\checkmark", "\\checkmark"),
                         c("State FE", "\\checkmark", "\\checkmark"),
                         c("N", get_n(mod_general_house), get_n(mod_general_senate), get_n(mod_primary_house), get_n(mod_primary_senate)),
                         c("Adj. R-squared", general_house_r2, general_senate_r2, primary_house_r2, primary_senate_r2)),
          out = "tables/reg-chamber.tex",
          label = "tab:reg-chamber")

